package com.sailer.practice.guava.Joiner;

import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import com.sailer.practice.model.Student;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Slf4j
public class JoinerStudy {
    private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("=");

    public static  void  testJoiner(){
        log.info(Joiner.on("; ").skipNulls().join("Harry", null, "Ron", "Hermione"));
        log.info(Joiner.on(",").join(Arrays.asList(1, 5, 7)));
        Map<String, String> queryParams = Maps.newHashMap();
        queryParams.put("a","1");
        queryParams.put("b","2");
        log.info(MAP_JOINER.join(queryParams));

        Student[] students = new Student[10];
        Student s1 = new Student("张三", 1);
        Student s2 = new Student("李四", 2);
        Student s3 = new Student("王五", 2);
        Student s4 = new Student("赵六", 2);

        students[0] = s1;
        students[1] = s2;
        students[2] = s3;
        students[3] = s4;
        log.info(Joiner.on("-----").skipNulls().join(students));
        log.info(Joiner.on("-----").useForNull("空对象").join(students));



        List studentList = new ArrayList<Student>();
        studentList.add(s1);
        studentList.add(s2);
        studentList.add(s3);
        studentList.add(s4);
        log.info(Joiner.on("-----").skipNulls().join(studentList));

    }


//    com.sailer.practice.guava.Joiner.JoinerStudy - Harry; Ron; Hermione
//    com.sailer.practice.guava.Joiner.JoinerStudy - 1,5,7
//    com.sailer.practice.guava.Joiner.JoinerStudy - a=1&b=2
//    com.sailer.practice.guava.Joiner.JoinerStudy - Student(name=张三, age=1)-----Student(name=李四, age=2)-----Student(name=王五, age=2)-----Student(name=赵六, age=2)
//    com.sailer.practice.guava.Joiner.JoinerStudy - Student(name=张三, age=1)-----Student(name=李四, age=2)-----Student(name=王五, age=2)-----Student(name=赵六, age=2)-----空对象-----空对象-----空对象-----空对象-----空对象-----空对象
//    com.sailer.practice.guava.Joiner.JoinerStudy - Student(name=张三, age=1)-----Student(name=李四, age=2)-----Student(name=王五, age=2)-----Student(name=赵六, age=2)
//

    public static void main(String[] args) {
        System.out.println(Joiner.on("; ").skipNulls().join("Harry", null, "", "Hermione"));


        testJoiner();

    }


}
